package tgc.edu.xzy.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import tgc.edu.xzy.entity.SysUser;
import tgc.edu.xzy.repostory.SysUserRepository;

@Component
public class UserUtils {
	@Autowired
	private SysUserRepository userDAO;
	
	public SysUser getUser() {
		UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String username = userDetails.getUsername();//得到用户名
		SysUser sysUser = userDAO.findByUsername(username);
		return sysUser;
	}
}
